package com.zhny.project.txt.history.controller;

import com.zhny.common.utils.poi.ExcelUtil;
import com.zhny.framework.aspectj.lang.annotation.Log;
import com.zhny.framework.aspectj.lang.enums.BusinessType;
import com.zhny.framework.web.controller.BaseController;
import com.zhny.framework.web.domain.AjaxResult;
import com.zhny.framework.web.page.TableDataInfo;
import com.zhny.project.txt.history.domain.TxtHistory;
import com.zhny.project.txt.history.service.ITxtHistoryService;
import com.zhny.project.txt.indexset.domain.TxtIndexset;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TXT处理记录Controller
 *
 * @author yanqun
 * @date 2019-12-11
 */
@Controller
@RequestMapping("/txt/history")
public class TxtHistoryController extends BaseController {
    private String prefix = "txt/history";

    @Autowired
    private ITxtHistoryService txtHistoryService;

    @RequiresPermissions("txt:history:view")
    @GetMapping()
    public String history() {
        return prefix + "/history";
    }

    /**
     * 查询TXT处理记录列表
     */
    @RequiresPermissions("txt:history:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TxtHistory txtHistory) {
        startPage();
        List<TxtHistory> list = txtHistoryService.selectTxtHistoryList(txtHistory);
        return getDataTable(list);
    }

    /**
     * 导出TXT处理记录列表
     */
    @RequiresPermissions("txt:history:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TxtHistory txtHistory) {
        List<TxtHistory> list = txtHistoryService.selectTxtHistoryList(txtHistory);
        ExcelUtil<TxtHistory> util = new ExcelUtil<TxtHistory>(TxtHistory.class);
        return util.exportExcel(list, "history");
    }

    /**
     * 新增TXT处理记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存TXT处理记录
     */
    @RequiresPermissions("txt:history:add")
    @Log(title = "TXT处理记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TxtHistory txtHistory) {
        return toAjax(txtHistoryService.insertTxtHistory(txtHistory));
    }

    /**
     * 修改TXT处理记录
     */
    @GetMapping("/edit/{historyKey}")
    public String edit(@PathVariable("historyKey") String historyKey, ModelMap mmap) {
        TxtHistory txtHistory = txtHistoryService.selectTxtHistoryById(historyKey);
        mmap.put("txtHistory", txtHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存TXT处理记录
     */
    @RequiresPermissions("txt:history:edit")
    @Log(title = "TXT处理记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TxtHistory txtHistory) {
        return toAjax(txtHistoryService.updateTxtHistory(txtHistory));
    }

    /**
     * 删除TXT处理记录
     */
    @RequiresPermissions("txt:history:remove")
    @Log(title = "TXT处理记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(txtHistoryService.deleteTxtHistoryByIds(ids));
    }

    //清除痕迹
    @GetMapping("/delte")
    public String delte(ModelMap modelMap) {
        int flag = 1;
        List<TxtIndexset> dele = txtHistoryService.deletedataset(flag);
        modelMap.put("dele", dele);
        return prefix + "/delte";
    }

    //清除痕迹保存
    @RequiresPermissions("txt:history:add")
    @Log(title = "TXT处理记录", businessType = BusinessType.INSERT)
    @PostMapping("/dele")
    @ResponseBody
    public AjaxResult TxtHistorydele(TxtHistory txtHistory) {
        return toAjax(txtHistoryService.TxtHistorydele(txtHistory));
    }

    //恢复
    @GetMapping("/recovery")
    public String recovery(ModelMap modelMap) {
        int flag = 1;
        List<TxtIndexset> dele = txtHistoryService.deletedataset(flag);
        modelMap.put("dele", dele);
        return prefix + "/recovery";
    }

    //恢复保存
    @RequiresPermissions("txt:history:add")
    @Log(title = "TXT处理记录", businessType = BusinessType.INSERT)
    @PostMapping("/recovery")
    @ResponseBody
    public AjaxResult txtrecovery(TxtHistory txtHistory)
    {
        return toAjax(txtHistoryService.txtrecovery(txtHistory));
    }
}
